
public class Outcast
{
	private final WordNet mWN;
	
	// constructor takes a WordNet object
	public Outcast(WordNet wordnet)
	{
		mWN = wordnet;
	}

	// given an array of WordNet nouns, return an outcast
	public String outcast(String[] nouns)
	{
		int maxDistance =  0;
		int maxIndex    = -1;
		for(int i = 0; i < nouns.length; i++)
		{
			int distance = 0;
			for(int k = 0; k < nouns.length; k++)
				if(i != k)
					distance += mWN.distance(nouns[i], nouns[k]);
			
			if(distance > maxDistance)
			{
				maxDistance = distance;
				maxIndex    = i;
			}
		}
		
		return nouns[maxIndex];
	}

	// for unit testing of this class (such as the one below)
	public static void main(String[] args)
	{
	    WordNet wordnet = new WordNet(args[0], args[1]);
	    Outcast outcast = new Outcast(wordnet);
	    for (int t = 2; t < args.length; t++) {
	        String[] nouns = In.readStrings(args[t]);
	        StdOut.println(args[t] + ": " + outcast.outcast(nouns));
	    }
	}
}
